//
//  PHStatusCell.swift
//  PHWeibo
//
//  Created by 潘荟 on 16/7/23.
//  Copyright © 2016年 BAT. All rights reserved.
//

import UIKit
import SnapKit
class PHStatusCell: UITableViewCell {
    //记录定不视图的顶部约束
    var toolBarBottomConstraint:Constraint?
    
    var statusViewModel:PHStatusViewModel?{
        didSet{
            originalView.statusViewModel = statusViewModel
            
            self.toolBarBottomConstraint?.uninstall()
            //没有转发微博
            if statusViewModel?.status?.retweeted_status == nil {
                
                toolBarView.snp_updateConstraints(closure: { (make) -> Void in
                    self.toolBarBottomConstraint = make.top.equalTo(originalView.snp_bottom).constraint
                })
                
                retweetView.hidden = true
            }else {
                
                //赋值,在自定义cell中重写set方法
                retweetView.statusViewModel = statusViewModel
                
                toolBarView.snp_updateConstraints(closure: { (make) -> Void in
                    self.toolBarBottomConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
                })
                
                retweetView.hidden = false
            }
        }
        
    }
    

    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 设置页面
    func setupUI() {
        
//        self.backgroundColor = RandomColor()
        //添加子控件
        contentView.addSubview(originalView)
        contentView.addSubview(retweetView)
        contentView.addSubview(toolBarView)
        
        //添加约束
        originalView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.top.equalTo(contentView)
//            make.height.equalTo(50)
        }
        
        retweetView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.leading.trailing.equalTo(contentView)
        }
        
        
        
        toolBarView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.equalTo(contentView)
            make.bottom.equalTo(contentView)
            make.height.equalTo(35)
        }
        
        
    }
    
    
    
    // MARK: - 懒加载子控件
    private lazy var originalView:PHStatusOriginalView = PHStatusOriginalView()
    
    private lazy var retweetView:PHStatusRetweetView = PHStatusRetweetView()
    
    private lazy var toolBarView:PHStatusToolBarView = PHStatusToolBarView()
    
    
    

}
